<template>
    <div>
        <!-- <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item class="w-[280px]" label="用户ID">
                    <el-input
                        v-model="queryParams.user_id"
                        placeholder="请输入用户ID"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                    <export-data
                        class="ml-2.5"
                        :fetch-fun="getPointsRecordList"
                        :params="queryParams"
                        :page-size="pager.size"
                    />
                </el-form-item>
            </el-form>
        </el-card> -->
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <!-- <el-table-column label="用户头像" min-width="100">
                    <template #default="{ row }">
                        <el-avatar :src="row.user_avatar" :size="50" />
                    </template>
                </el-table-column> -->
                <!-- <el-table-column label="用户昵称" prop="user_nickname" min-width="120" /> -->
                <!-- <el-table-column label="用户账号" prop="user_account" min-width="120" /> -->
                <el-table-column label="记录时间" prop="create_time" min-width="160" />
                <el-table-column label="积分数量" min-width="120">
                    <template #default="{ row }">
                        <span :class="row.type === 1 ? 'text-green-600' : 'text-red-600'">
                            {{ row.type === 1 ? '+' : '-' }}{{ row.number }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="积分类型" min-width="100">
                    <template #default="{ row }">
                        <el-tag :type="row.type === 1 ? 'success' : 'danger'">
                            {{ row.type === 1 ? '增加' : '扣除' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="积分来源" min-width="120">
                    <template #default="{ row }">
                        {{ row.content }}
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="remark" min-width="200" show-overflow-tooltip />
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup name="pointsRecord">
import { usePaging } from '@/hooks/usePaging'
import { apiUserPoint } from '@/api/port'
import { useRoute } from 'vue-router'

// 使用真实的API接口获取积分记录
const getPointsRecordList = apiUserPoint

const route = useRoute()

const queryParams = reactive({
    user_id: route.query.id as string,
    page_no: 1,
    page_size: 10
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: apiUserPoint,
    params: queryParams
})

// 获取积分来源文本
const getSourceText = (source: string) => {
    const sourceMap: Record<string, string> = {
        order: '下单',
        note: '发布笔记',
        checkin: '签到',
        invite: '邀请好友',
        system: '系统奖励',
        admin: '管理员调整'
    }
    return sourceMap[source] || source
}

onActivated(() => {
    getLists()
})

getLists()
</script>